#pragma once
#include "ace/Asynch_Acceptor.h"
#include "ServerHandler.h"

class AsyncAcceptor : public ACE_Asynch_Acceptor< CServerHandler >
{
public:
	AsyncAcceptor( IMessageQueue *pMessageQueue );
	~AsyncAcceptor(void);

	/// This initiates a new asynchronous accept operation.
	/**
	* You need only call this method if the @a reissue_accept argument
	* passed to @c open() was 0.
	*/
	virtual int accept(size_t bytes_to_read = 0, const void *act = 0 );

	/**
	* Template method to validate peer before service is opened.
	* This method is called after a new connection is accepted if the
	* @a validate_connection argument to @c open() was non-zero or
	* the @c validate_new_connection() method is called to turn this
	* feature on.  The default implementation returns 0.  Users can
	* reimplement this method to perform validation of the peer
	* using it's address, running an authentication procedure (such as
	* SSL) or anything else necessary or desireable. The return value
	* from this method determines whether or not ACE will continue
	* opening the service or abort the connection.
	*
	* @param result    Result of the connection acceptance.
	* @param remote    Peer's address.
	* @param local     Local address connection was accepted at.
	*
	* @retval  -1  ACE_Asynch_Acceptor will close the connection, and
	*              the service will not be opened.
	* @retval  0   Service opening will proceeed.
	*/
	virtual int validate_connection (const ACE_Asynch_Accept::Result& result,
		const ACE_INET_Addr &remote,
		const ACE_INET_Addr& local);

private:
	IMessageQueue *m_pMessageQueue;
};
